<include file="public@header"/>
<style>
    .data-item-tr, .search-btn {
        cursor: pointer;
    }

    .col-xs-3 {
        padding-right: 0;
    }
</style>
</head>
<body>
<div class="wrap js-check-wrap">
    <notempty name="filters">
        <form method="post" action="{:url('theme/dataSource')}" id="search-form">
            <div class="row">
                <foreach name="filters" item="filter" key="filterName">
                    <switch name="filter.type">
                        <case value="text">
                            <div class="col-xs-3">
                                <div class="form-group">
                                    <label class="sr-only">{$filter.title|default=''}</label>
                                    <input type="text" class="form-control" name="{$filterName}"
                                           placeholder="{$filter.placeholder|default=''}"
                                           value="{$form[$filterName]|default=''}">
                                </div>
                            </div>
                        </case>
                        <case value="select">
                            <div class="col-xs-3">
                                <div class="form-group">
                                    <label class="sr-only">{$filter.title|default=''}</label>
                                    <select class="form-control" name="{$filterName}">
                                        <notempty name="filter.placeholder">
                                            <option value="">{$filter.placeholder|default=''}</option>
                                        </notempty>
                                        <foreach name="filter.options" item="option">
                                            <php>
                                                $option_selected='';
                                                if(isset($form[$filterName]) &&  $form[$filterName]==$option['id']){
                                                    $option_selected='selected';
                                                };
                                            </php>
                                            <option value="{$option.id}" {$option_selected}>{$option.name}</option>
                                        </foreach>
                                    </select>
                                </div>
                            </div>
                        </case>
                    </switch>
                </foreach>
                <div class="col-xs-3">
                    <input type="hidden" value="{$data_source}" name="data_source">
                    <button type="submit" class="btn btn-primary">搜索</button>
                    <a class="btn btn-danger" href="">清空</a>
                </div>
            </div>
            <!--<div class="form-group">-->
            <!--<div class="input-group">-->
            <!--<input type="text" class="form-control" name="keyword" value="{$keyword|default=''}"-->
            <!--placeholder="请输入关键字">-->
            <!--<input type="hidden" value="{$data_source}" name="data_source">-->
            <!--<span class="input-group-addon search-btn" onclick="submitSearchForm()">GO!</span>-->
            <!--</div>-->
            <!--</div>-->
        </form>
    </notempty>
    <form method="post" class="js-ajax-form">

        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="16">
                    <if condition="$multi">
                        <label>
                            <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                        </label>
                    </if>
                </th>
                <th width="50">ID</th>
                <th>名称</th>
            </tr>
            </thead>
            <tbody>
            {$items_tree}
            </tbody>
        </table>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script>
    $('.data-item-tr').click(function (e) {

        console.log(e);
        var $this = $(this);
        if ($(e.target).is('input')) {
            return;
        }

        var $input = $this.find('input');
        if ($input.is(':checked')) {
            $input.prop('checked', false);
        } else {
            $input.prop('checked', true);
        }


    });

    function submitSearchForm() {
        $('#search-form').get(0).submit();
    }

    function confirm() {
        var selectedObjectsId   = [];
        var selectedObjectsName = [];
        var selectedObjects     = [];
        $('.js-select-box:checked').each(function () {
            var $this = $(this);
            selectedObjectsId.push($this.val());
            selectedObjectsName.push($this.data('name'));

            selectedObjects.push({
                id: $this.val(),
                name: $this.data('name')
            });
        });

        return {
            selectedObjects: selectedObjects,
            selectedObjectsId: selectedObjectsId,
            selectedObjectsName: selectedObjectsName
        };
    }
</script>
</body>
</html>